/*******************************************************************/
/* @ All Rights Reserved Copyright (C) 2014 broada,Ltd.            */
/*                                                                 */
/*  NAME      = t_sqlserver_destroy_request.c                      */
/*  NOTE      =                                                    */
/*  DATE      = 2014/12/09 by geyh                                 */
/*******************************************************************/

#include <stdio.h>
#include <string.h>
#include <CUnit/Basic.h>

#include <frcomm.h>
#include <sqlserver/config.h>
#include <sqlserver/sqlserver_core.h>
#include <sqlserver/sqlserver_common.h>

static int __suite_init(void)
{

	return 0;
}

static int __suite_cleanup(void)
{

	return 0;
}

static void __case1(void)
{
    L7_req_sqlserver **pp_st_request;

    pp_st_request = NULL;

    sqlserver_destroy_request(pp_st_request);

    return;
}

static void __case2(void)
{
    L7_req_sqlserver *p_st_request = NULL;

    sqlserver_destroy_request(&p_st_request);

    return;
}

static void __case3(void)
{
    L7_req_sqlserver *p_st_request = NULL;

    p_st_request = (L7_req_sqlserver *) frmalloc(sizeof(L7_req_sqlserver));
    memset(p_st_request, 0x00, sizeof(L7_req_sqlserver));

    p_st_request->p_st_statement = (Sql_statement *) frmalloc(sizeof(Sql_statement));
    memset(p_st_request->p_st_statement, 0x00, sizeof(Sql_statement));

    p_st_request->u8_request_type = MSSQL_TDS_RPCREQUEST;

    sqlserver_destroy_request(&p_st_request);

    CU_ASSERT_PTR_NULL(p_st_request);

    return;
}

int add_suite_sqlserver_destroy_request(void)
{
    CU_pSuite pSuite = NULL;

    if ((pSuite = CU_add_suite(MODULE_NAME" sqlserver_destroy_request()", __suite_init, __suite_cleanup)) == NULL)
    return FR_FAIL;

    //增加测试用例
    if (CU_add_test(pSuite, "case1", __case1) == NULL ||
        CU_add_test(pSuite, "case2", __case2) == NULL ||
        CU_add_test(pSuite, "case3", __case3) == NULL)
        return FR_FAIL;

    return FR_SUCC;
}
